package com.gitee.hifong45.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.MapPropertySource;

import com.gitee.hifong45.Kv;

import cn.hutool.core.lang.Console;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.env.ConfigurableEnvironment;

@Slf4j
@Configuration
public class ExtEnvironment implements EnvironmentPostProcessor {
    String SUFFIX_MANAGEMENT = "management";
    String SUFFIX_DATABASE = "spring.datasource";
    String SUFFIX_MYBATIS_PLUS = "mybatis-plus";

    private Map<String, Object> source = Kv.of(
        "spring.resources.static-locations", "file:./static/,file:./public/",
        SUFFIX_MANAGEMENT + "." + "server.port", "12346",
        SUFFIX_MANAGEMENT + "." + "endpoints.web.exposure.include", "info,health,loggers",
        SUFFIX_MANAGEMENT + "." + "endpoints.web.base-path", "/onlydev",

        SUFFIX_DATABASE + "." + "driver-class-name", "org.h2.Driver",
        SUFFIX_MYBATIS_PLUS + "." + "configuration.log-impl", "com.gitee.hifong45.MyBatisLogImpl"
    );
    @Override
    public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
        Console.log("environment post processor ext-env= {}", source);
        MapPropertySource propertySource = new MapPropertySource("extevn", source);
        environment.getPropertySources().addLast(propertySource);
        log.debug("set ext-env over");
        Console.log("IP:PORT/ext/loglevel?clz=class&rw=&level=INFO");
        System.out.println("set ext-env over");
        
    }

}
